package com.question.view.command;

import com.question.entity.User;
import com.question.service.ISeedtimeService;
import com.question.service.impl.SeedtimeServiceImpl;
import com.question.utils.InputOutUtils;

public class SignupCommand implements INoLoginCommand{
	private ISeedtimeService SeedtimeService = new SeedtimeServiceImpl();
	@Override
	//1输入用户名密码
	//2验证用户名是否已经存在
	public void exec() {
		while(true) {
			String username = InputOutUtils.inputString("请输入用户名:", false);
			if(SeedtimeService.existUserByUsername(username)) {
				String password = InputOutUtils.inputString("请输入密码:", false);
				String displayName = InputOutUtils.inputString("请输入显示的昵称:", false);
				User user = new User(username, password);
				user.setDisplay_name(displayName);
				SeedtimeService.signup(user);
				break;
			}else {
				InputOutUtils.print("你输入的用户名已经存在");
				if("N".equalsIgnoreCase(InputOutUtils.inputString("是否重试[YorN]:", false)))break;
			}
		}
	}

}
